<!--
@author  tanyuze
@desc    完成条件
@date    2022/11/24
-->
<template>
  <div class="escrow-list">
    <el-collapse-transition>
      <section v-show="searchShow" class="main-search merge">
        <span class="svg-container">
          <svg-icon icon-class="search" />
        </span>
        <el-input
          v-model.trim="listQuery.seriesName"
          placeholder="输入名称搜索"
          class="search-input"
          @keyup.enter.native="handleFilter"
        />
        <section class="search-btn">
          <el-button class="filter-item" type="primary" @click="handleFilter">搜索</el-button>
          <el-button type="primary" @click="handleReset">重置</el-button>
          <!--          <span class="search-more" @click="searchShow = !searchShow">
            更多筛选条件
            <i class="el-icon-arrow-down" />
          </span>-->
        </section>
      </section>
    </el-collapse-transition>
    <el-collapse-transition>
      <section v-show="!searchShow" class="main-search separate">
        <section class="search-inner">
          <el-row>
            <el-col :span="12">
              <section class="search-inner-item">
                <div class="item-label">新闻标题</div>
                <el-input
                  v-model.trim="search.title"
                  style="width: 90%;"
                  class="filter-item"
                  placeholder="请输入新闻标题搜索"
                />
              </section>
            </el-col>
          </el-row>
        </section>
        <section class="search-btn">
          <el-button type="primary" @click="handleFilter">搜索</el-button>
          <el-button type="primary" @click="handleReset">重置</el-button>
          <span class="search-more" @click="searchShow = !searchShow">
            精简筛选条件
            <i class="el-icon-arrow-up" />
          </span>
        </section>
      </section>
    </el-collapse-transition>

    <div class="page-btn">
      <div class="page-title">
        <span>完成条件</span>
      </div>
      <div class="page-btns">
        <el-button style="margin-left: 10px;" @click="handleCreated">新建 </el-button>
        <!--        <el-button style="margin-left: 10px;" @click="handleDeletes">批量删除 </el-button>-->
        <!--        <el-button style="margin-left: 10px;" @click="handleBack">返回 </el-button>-->
      </div>
    </div>

    <div class="page-main-list">
      <v-table
        :list="list"
        tag="seriesList"
        :source-arr="sourceArr"
        :selection="false"
        :list-loading="listLoading"
        :filter-column="filterColumn"
        @handleSelectionChange="handleSelectionChange"
      >
        <el-table-column fixed="right" label="操作" width="160" align="center">
          <template slot-scope="scope">
            <el-button type="text" size="small" @click="handlePublish(scope.row)"> {{ scope.row.status === 'ZT01' ? '禁用' : '启用' }}</el-button>
            <el-button type="text" size="small" @click="handleRelation(scope.row)">关联条件</el-button>
            <el-button type="text" size="small" @click="handleUpdate(scope.row)">编辑</el-button>
            <el-button type="text" size="small" @click="handleDel(scope.row)">删除</el-button>
          </template>
        </el-table-column>
      </v-table>
    </div>

    <pagination v-show="total > 0" :total="total" :page.sync="listQuery.page" :limit.sync="listQuery.limit" @pagination="getPage" />
  </div>
</template>
<script>
import Pagination from '@/components/Pagination'
import { honorSeriesPage, honorSeriesDel, honorSeriesUpdate } from '../api'
import elDragDialog from '@/directive/el-drag-dialog'
import vTable from '@/components/Table'

export default {
  name: 'Escrow',
  components: { Pagination, vTable },
  directives: { elDragDialog },
  data() {
    return {
      /* search*/
      searchShow: true,
      total: 0,
      listQuery: {
        page: 1,
        limit: 10,
        seriesName: ''
      },
      search: {
        title: ''
      },

      /* table*/
      list: [],
      listLoading: false,
      sourceArr: [],

      /* user-defined*/
      view: '/API-DOCUMENT/document/file/download?id='
    }
  },
  computed: {
    /* tag() {
      return this.tagList[this.activeTab]
    }*/
  },
  watch: {
    /* activeTab() {
      this.myTime = new Date().getTime()
    }*/
  },
  created() {
    this.getPage()
  },
  methods: {
    filterColumn(scope, item) {
      if (item === 'isHaveTime') {
        return scope.row[item] === 0 ? '否' : '是'
      }
      return scope.row[item]
    },
    handleCreated() {
      this.$router.push({ path: this.$filterPath('escrowManage'), query: { type: 'c' }})
    },
    handleUpdate(row) {
      this.$router.push({ path: this.$filterPath('escrowManage'), query: { type: 'u', i: row.id }})
    },
    handleRelation(row) {
      this.$router.push({ path: this.$filterPath('joinCondition'), query: { i: row.id, seriesType: row.seriesType }})
    },
    select() {

    },
    /**
     * 启用/禁用
     */
    handlePublish(row) {
      this.$confirm(row.status === 'ZT01' ? '确认禁用？' : '确认启用？', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        honorSeriesUpdate({ id: row.id, status: row.status === 'ZT01' ? 'ZT02' : 'ZT01' }).then(res => {
          if (res.data.code === '200') {
            this.$message({
              type: 'success',
              message: '操作成功!'
            })
            this.getPage()
          }
        })
      }).catch(() => {

      })
    },

    /**
     *多选
     */
    handleSelectionChange(arr) {
      this.multipleSelection = arr
    },
    handleBack() {
      this.$router.back()
    },
    /**
     * 删除
     */
    handleDel(row) {
      this.$confirm('此操作将永久删除该数据, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      })
        .then(() => {
          const loading = this.$loading({
            lock: true,
            text: '请稍后',
            spinner: 'el-icon-loading',
            background: 'rgba(0, 0, 0, 0.3)'
          })
          return new Promise((resolve, reject) => {
            honorSeriesDel({
              id: row.id
            })
              .then(() => {
                loading.close()
                this.$message({
                  title: '成功',
                  message: '删除成功',
                  type: 'success',
                  duration: 2000
                })
                this.getPage()
              })
              .catch((error) => {
                loading.close()
                reject(error)
              })
          })
        })
        .catch(() => {})
    },

    /**
     * 获取列表
     */
    getPage(obj) {
      this.listLoading = true
      var query = {
        page: obj ? obj.page : this.listQuery.page,
        pageSize: obj ? obj.limit : this.listQuery.limit
      }
      if (this.searchShow) {
        query['seriesName'] = this.listQuery.seriesName
      } else {
        query['seriesType'] = this.search.seriesType
      }
      return new Promise((resolve, reject) => {
        honorSeriesPage(query)
          .then((response) => {
            this.listLoading = false
            this.list = response.data.data.rows
            this.total = response.data.data.total
          })
          .catch((error) => {
            this.listLoading = false
            reject(error)
          })
      })
    },

    /**
     *搜索
     */
    handleFilter() {
      this.listQuery.page = 1
      this.getPage()
    },

    /**
     *重置
     */
    handleReset() {
      this.listQuery.seriesName = ''
      this.listQuery.title = ''
      this.listQuery.page = 1
      this.getPage()
    }
  }
}
</script>
<style rel="stylesheet/scss" lang="scss">
$dark_gray: #bfced6;
.escrow-list {
  padding: 10px;

  .main-search {
    background-color: #fff;
    padding: 0 10px;
    .svg-container {
      padding: 0 5px 0 10px;
      color: #bfced6;
      vertical-align: middle;
      display: inline-block;
    }
    .search-input {
      width: 60%;
      position: relative;
      &:after {
        content: '';
        position: absolute;
        left: -25px;
        right: 0;
        bottom: 8px;
        height: 1px;
        background: rgba(226, 227, 232, 1);
      }
      input {
        outline: none;
        background: transparent;
        border: none;
        outline: medium;
        padding: 0;
        &:focus {
          outline: none;
          background-color: transparent;
        }
      }
    }
    .search-btn {
      display: inline-block;
      float: right;
      .el-button.is-round {
        padding: 10px 30px;
        margin-right: 34px;
      }
      .search-more {
        font-size: 14px;
        font-weight: 500;
        @include font-color($mainColor);
        cursor: pointer;
        margin-left: 10px;
      }
    }

    &.merge {
      height: 50px;
      line-height: 50px;
    }

    &.separate {
      .search-inner {
        padding-top: 10px;
        .search-inner-item {
          .item-label {
            height: 30px;
            line-height: 30px;
            font-size: 14px;
            color: #a6a6a6;
            font-weight: 400;
          }
          .el-input {
            position: relative;
            &.el-date-editor input {
              padding-left: 30px;
            }
            .el-input__inner {
              border: none;
              padding: 0;
            }
            &:after {
              content: '';
              height: 1px;
              background-color: #e2e3e8;
              position: absolute;
              left: 0;
              right: 0;
              bottom: 0;
            }
          }
        }
      }
      .search-btn {
        text-align: center;
        display: block;
        float: none;
        height: 56px;
        line-height: 56px;
      }
    }
  }

  .page-btn {
    display: flex;
    height: 46px;
    line-height: 46px;
    width: 100%;

    .page-title {
      flex: 1;
      font-size: 16px;
      font-weight: bold;
      color: rgba(51, 51, 51, 1);
    }
  }

  .page-tabs {
    width: 100%;
    margin: 10px 0;
    padding: 0 10px;
    background-color: #fff;
    border-radius: 4px;

    .el-tabs__nav-next {
      line-height: 40px;
    }

    .el-tabs__nav-wrap::after {
      display: none;
    }

    .el-tabs__header {
      margin: 0;
    }
  }

  .page-main-list {
    .el-image {
      width: 100%;
      height: auto;
      max-height: 140px;
    }
  }

  .pagination-container {
    background: none;
  }

}
</style>
